<?php
class AdvertModel extends Model {

	protected $tableName = 'advert';
	protected $fields = array(
			0=>'aid',
			1=>'title',
			2=>'content',
			3=>'pic',
			4=>'author',
			5=>'ctime',
			6=>"pid",
			7=>"visit_num",
			8=>"share_num",
			9=>"is_display",
			10=>"is_forbidden",
			11=>"is_del",
			12=>"status",
			13=>"ctime",
			14=>"is_link",
			15=>"link",
			16=>"is_banner",
	);

	public function getAdvertList($limit = 20,array $map = array(),$order = "aid DESC"){
		// 添加用户表的查询，用于关联查询
		if (isset ( $_POST )) {
			$_POST ['aid'] && $map ['aid'] = intval ( $_POST ['aid'] );
			$_POST ['title'] && $map ['title'] = t ( $_POST ['title'] );
			$_POST ['content'] && $map ['content'] = t ( $_POST ['content'] );
			$_POST ['pid'] && $map ['pid'] = t ( $_POST ['pid'] );
			$_POST ['visit_num'] && $map ['visit_num'] = t ( $_POST ['visit_num'] );
			$_POST ['share_num'] && $map ['share_num'] = t ( $_POST ['share_num'] );
			isset($_POST ['is_display']) && $map ['is_display'] = t ( $_POST ['is_display'] );
			isset($_POST ['is_forbidden']) && $map ['is_forbidden'] = t ( $_POST ['is_forbidden'] );
			isset($_POST ['is_del']) && $map ['is_del'] = t ( $_POST ['is_del'] );
			isset($_POST ['status']) && $map ['status'] = t ( $_POST ['status'] );
			isset($_POST ['is_banner']) && $map ['is_banner'] = t ( $_POST ['is_banner'] );
			// 注册时间判断，ctime为数组格式
			if (! empty ( $_POST ['ctime'] )) {
				if (! empty ( $_POST ['ctime'] [0] ) && ! empty ( $_POST ['ctime'] [1] )) {
					// 时间区间条件
					$map ['ctime'] = array (
							'BETWEEN',
							array (
									strtotime ( $_POST ['ctime'] [0] ),
									strtotime ( $_POST ['ctime'] [1] )
							)
					);
				} else if (! empty ( $_POST ['ctime'] [0] )) {
					// 时间大于条件
					$map ['ctime'] = array (
							'GT',
							strtotime ( $_POST ['ctime'] [0] )
					);
				} elseif (! empty ( $_POST ['ctime'] [1] )) {
					// 时间小于条件
					$map ['ctime'] = array (
							'LT',
							strtotime ( $_POST ['ctime'] [1] )
					);
				}
			}
				
		}

		// 查询数据
		$list = $this->where ($map)->order ( $order )->findPage ( $limit );
		
		
		
		return $list;
	
	}
}
